<%@page import="models.OrderProductModel"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.Map"%>
<%@page import="admin.data.CoordinaData"%>
<%@page import="java.util.TreeMap"%>
<%@page import="models.OrderModel"%>
<%@page import="java.util.List"%>
<%@page import="models.StaffModel"%>
<%@page import="models.RouteModel"%>
<%@page import="models.CoordinaModel"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	CoordinaModel coordinaModel = (CoordinaModel) request.getAttribute("coordinaModel");
	RouteModel route = (RouteModel) request.getAttribute("route");
	StaffModel staff = (StaffModel) request.getAttribute("staff");
	TreeMap<String, OrderProductModel> mapOrderProduct = (TreeMap<String, OrderProductModel>) request.getAttribute("mapOrderProduct");
	int totalPrice = (Integer) request.getAttribute("totalPrice");
	int expectedPrice = (Integer) request.getAttribute("expectedPrice");
	int totalVC = (Integer) request.getAttribute("totalVC");
	int totalSP = (Integer) request.getAttribute("totalSP");
	NumberFormat nf = NumberFormat.getInstance();
	SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
	List<OrderModel> listOrder = (List<OrderModel>) request.getAttribute("listOrder");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tuyến giao nhận</title>
<link rel="stylesheet" type="text/css" href="/css/simple-style.css" />
<style>
	@media print {
		input[type="button"] {
			display: none;
		}
		div.simpleStyle {
			margin-top: 200px;
		}
	}
</style>
</head>
<body>
	<table cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;line-height: 1.3;margin-bottom: 20px;font-family: Arial, Helvetica, sans-serif;font-size: 75%;">
    	<tbody>
        	<tr>
            	<td width="20%" valign="top">
            		<input type="button" onclick="window.print()" value="In tuyến">            		
                	<div style="margin-bottom: 40px;">
                    	<h3><%=route.getName() %> (<%=coordinaModel.getId() %>)</h3>
                        <strong>Ngày xuất tuyến : </strong> <%=formatDate.format(coordinaModel.getCreated()) %>
                        <br />
                        <strong>Ngày về : </strong>
                        <br />
                        <strong>Tổng tiền đơn hàng : </strong> <%=nf.format(totalPrice) %>đ
                        <br />
                        <strong>Tổng tiền dự kiến thu : </strong> <%=nf.format(expectedPrice) %>đ
                        <br />
                        <strong>Tổng tiền thực thu : </strong>
                    </div>
                    <table cellpadding="5" cellspacing="0" width="100%" border="#000" style="border-collapse:collapse;text-align:center;color:#aaa;font-weight:bold;" class="simpleTable">
                        <tbody>
                            <tr valign="top">
                                <td height="125">Giao nhận ký nhận phiếu</td>
                                <td height="125">Điều phối ký giao phiếu</td>
                            </tr>
                            <tr valign="top">
                                <td height="125">Giao nhận ký nhận hàng</td>
                                <td height="125">Kho ký nhận giao hàng</td>
                            </tr>
                            <tr valign="top">
                                <td height="125">Điều phối ký nhận phiếu</td>
                                <td height="125">Kho ký nhận hàng</td>
                            </tr>
                        </tbody>
                    </table>
                </td>
                <td width="80%" valign="top">
                	<div style="text-align:right;padding-right:100px;">
                        <strong><%=staff.getName() %></strong>
                        <br />
                        <strong>ID nhân viên : <%=staff.getCode() %></strong>
                    </div>
                    <% if(totalVC>0) { %>
                    <table cellpadding="10" cellspacing="0" width="100%" style="border-collapse:collapse;margin-bottom:20px;">
                    	<tbody>
                        	<tr valign="top">
                            	<td width="50%">
                                	<table cellpadding="5" cellspacing="0" width="100%" border="#000" style="border-collapse:collapse;text-align:center;" class="simpleTable">
                                        <thead>
                                            <tr>
                                                <th>STT</th>
                                                <th width="50%">Tên phiếu</th>
                                                <th width="15%">SL cần giao</th>
                                                <th width="15%">SL thực giao</th>
                                                <th width="15%">SL trả về</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <% int i = 1;
                                            	for (Map.Entry<String, OrderProductModel> entry : mapOrderProduct.entrySet()) {
                                            		if((entry.getValue().getStoreType()==0)&&(i%2==1)) { %>                              
			                                <tr>
			                                    <td><%=i %></td>
			                                    <td align="left">[<%=entry.getValue().getProductId() %>]<%=entry.getValue().getName() %></td>
			                                    <td><%=entry.getValue().getQuantity() %></td>
			                                    <td></td>
			                                    <td>&nbsp;</td>
			                                </tr>
			                                <% } if(entry.getValue().getStoreType()==0) {i++;} } %>                                      
                                        </tbody>
                                    </table>
                                </td>
                                <td>
                                	<% if(totalVC>1) { %>                               
                                	<table cellpadding="5" cellspacing="0" width="100%" border="#000" style="border-collapse:collapse;text-align:center;" class="simpleTable">
                                        <thead>
                                            <tr>
                                                <th>STT</th>
                                                <th width="50%">Tên phiếu</th>
                                                <th width="15%">SL cần giao</th>
                                                <th width="15%">SL thực giao</th>
                                                <th width="15%">SL trả về</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <% 
                                            	int j = 1;
                                            	for (Map.Entry<String, OrderProductModel> entry : mapOrderProduct.entrySet()) { 
                                            		if((entry.getValue().getStoreType()==0)&&(j%2==0)) { %>                              
			                                <tr>
			                                    <td><%=j %></td>
			                                    <td align="left">[<%=entry.getValue().getProductId() %>]<%=entry.getValue().getName() %></td>
			                                    <td><%=entry.getValue().getQuantity() %></td>
			                                    <td></td>
			                                    <td>&nbsp;</td>
			                                </tr>
			                                <% } if(entry.getValue().getStoreType()==0) {j++;} } %>                                       
                                        </tbody>
                                    </table>
                                     <% } %>
                                </td>                               
                            </tr>
                        </tbody>
                    </table>
                    <% } %>
                    <% if(totalSP>0) { %>                    
                    <table cellpadding="10" cellspacing="0" width="100%" style="border-collapse:collapse;margin-bottom:20px;">
                    	<tbody>
                        	<tr valign="top">
                            	<td width="50%">
                                	<table cellpadding="5" cellspacing="0" width="100%" border="#000" style="border-collapse:collapse;text-align:center;" class="simpleTable">
                                        <thead>
                                            <tr>
                                                <th>STT</th>
                                                <th width="50%">Tên sản phẩm</th>
                                                <th width="15%">SL cần giao</th>
                                                <th width="15%">SL thực giao</th>
                                                <th width="15%">SL trả về</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <% 
                                            	int k = 1;
                                            	for (Map.Entry<String, OrderProductModel> entry : mapOrderProduct.entrySet()) { 
                                            		if((entry.getValue().getStoreType()==1)&&(k%2==1)) { %>                              
			                                <tr>
			                                    <td><%=k %></td>
			                                    <td align="left">[<%=entry.getValue().getProductId() %>]<%=entry.getValue().getName() %></td>
			                                    <td><%=entry.getValue().getQuantity() %></td>
			                                    <td></td>
			                                    <td>&nbsp;</td>
			                                </tr>
			                                <% } if(entry.getValue().getStoreType()==1) {k++;} } %>                                      
                                        </tbody>
                                    </table>
                                </td>
                                <td>
                                	<% if(totalSP>1) { %>                                	
                                	<table cellpadding="5" cellspacing="0" width="100%" border="#000" style="border-collapse:collapse;text-align:center;" class="simpleTable">
                                        <thead>
                                            <tr>
                                                <th>STT</th>
                                                <th width="50%">Tên sản phẩm</th>
                                                <th width="15%">SL cần giao</th>
                                                <th width="15%">SL thực giao</th>
                                                <th width="15%">SL trả về</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <% 
                                            	int l = 1;
                                            	for (Map.Entry<String, OrderProductModel> entry : mapOrderProduct.entrySet()) { 
                                            		if((entry.getValue().getStoreType()==1)&&(l%2==0)) { %>                              
			                                <tr>
			                                    <td><%=l %></td>
			                                    <td align="left">[<%=entry.getValue().getProductId() %>]<%=entry.getValue().getName() %></td>
			                                    <td><%=entry.getValue().getQuantity() %></td>
			                                    <td></td>
			                                    <td>&nbsp;</td>
			                                </tr>
			                                <% } if(entry.getValue().getStoreType()==1) {l++;} } %>                                      
                                        </tbody>
                                    </table>
                                    <% } %>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <% } %>
                </td>
            </tr>
        </tbody>
    </table>    
    <div class="simpleStyle">
    	<table cellpadding="0" cellspacing="0" class="simpleTable">
        	<thead>
            	<tr>
                	<th>STT</th>
                    <th>Đơn hàng</th>
                    <th>Phiếu / Sản phẩm</th>
                    <th>SL</th>
                    <th>khách hàng</th>
                    <th>Điện thoại</th>
                    <th>Số tiền phải thu</th>
                    <th>KH ký tên đã nhận hàng</th>
                    <th width="30%">Ghi chú</th>
                </tr>
            </thead>
            <tbody>            	
            	<% for (int i = 0; i < listOrder.size(); i++) { %>
                	<tr>
	                	<td align="center"><%=i+1 %></td>
	                    <td>
	                    	<strong><%=listOrder.get(i).getOrderId() %></strong>
	                        <br />
	                       	<%=formatDate.format(listOrder.get(i).getOrderDate()) %>
	                    </td>
	                    <td>
	                    	<%
	                    		List<String> listOrderProduct = listOrder.get(i).getListOrderProduct();
								for (String stringOrderProduct : listOrderProduct) {
									OrderProductModel orderProduct = new OrderProductModel();
									orderProduct.getValueFromString(stringOrderProduct);
									if(orderProduct.getQuantity()>0)
									{
										out.print("["+orderProduct.getProductId()+"]");
										out.print(orderProduct.getName()+" ["+orderProduct.getQuantity()+"]");
										out.print("<br \\/>");
									}
								}
	                    	%>
	                        Giá bán : <%=nf.format(listOrder.get(i).getUnitPrice()) %>đ
	                    </td>
	                    <td align="center"><%=listOrder.get(i).getQuantity() %></td>
	                    <td>
	                    	<strong>Tên : </strong><%=listOrder.get(i).getShipName() %>
	                        <br />
	                        <strong>Địa chỉ : </strong><%=listOrder.get(i).getShipAddressFull() %>
	                        <br />
	                        <p class="note"><%=listOrder.get(i).getNote() %></p>
	                    </td>
	                    <td align="center"><%=listOrder.get(i).getShipPhoneNumber() %></td>
	                    <td align="center"><% if(!listOrder.get(i).isCheckOut()) { out.print(nf.format(listOrder.get(i).getTotalPrice())+"đ"); } %></td>
	                    <td>
	                    	<%=i+1 %> - <%=listOrder.get(i).getShipName() %>
	                    </td>
	                    <td><p class="note"></p></td>
                    </tr>
                 <% } %>                                
            </tbody>
        </table>
    </div>
</body>
</html>